<!--<template>-->

<!--  <h1>111</h1>-->
<!--&lt;!&ndash;  <router-view></router-view>&ndash;&gt;-->
<!--</template>-->

<!--<script>-->
<!--export default {-->
<!--  name: "Login"-->
<!--};-->
<!--</script>-->

<!--<style scoped>-->

<!--</style>-->

<template>
  <router-view></router-view>
  <div class="login-container">
    <h2>请登录</h2>
    <form @submit.prevent="login">
      <div class="form-group">
        <input type="username" v-model="username" placeholder="用户名" required>
      </div>
      <div class="form-group">
        <input type="password" v-model="password" placeholder="密码" required>
      </div>
      <button type="submit">登录</button>
      <h1></h1>

    </form>
    <button @click="toRegister">注册</button>
  </div>
</template>

<script>
import router from "@/router";
import sysMapping from  "@/settings/sysMapping"
import axios from "@/settings/axios";

export default {
  name: "Login",
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login:async function () {
      // 在此处添加登录逻辑
      console.log('username:', this.username);
      console.log('Password:', this.password);

      let loginInVO = {
        "username": this.username,
        "password": this.password
      }

      // let userInfo = await axios.post( "/api/SysUser/login",loginInVO);
      let tokenInfo = await axios.post( "SysUser/login",loginInVO);

      console.log(tokenInfo);
      console.log(tokenInfo.message)
      console.log(tokenInfo.token)
      localStorage.setItem(sysMapping.TOKEN,tokenInfo.token);
      console.log(localStorage.getItem(sysMapping.TOKEN))
      // alert("登录成功，除了登录注册别的页面还没做");
      router.push("/shane/home");



      // 清空表单字段
      this.username = '';
      this.password = '';
    },
    toRegister() {
      router.push({path:"/user/register"});
    }
  }
}
</script>

<style scoped>
.login-container {
  max-width: 350px;
  margin: 0 auto;
  padding: 20px;
  background: #f2f2f2;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  text-align: center;
}

h2 {
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

input[type="username"],
input[type="password"] {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

button {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  background: #4CAF50;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: #45a049;
}
</style>
